#!/usr/bin/perl -wT
# -*- Mode: perl; indent-tabs-mode: nil -*-
#
# The contents of this file are subject to the Mozilla Public
# License Version 1.1 (the "License"); you may not use this file
# except in compliance with the License. You may obtain a copy of
# the License at http://www.mozilla.org/MPL/
#
# Software distributed under the License is distributed on an "AS
# IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
# implied. See the License for the specific language governing
# rights and limitations under the License.
#
# The Original Code is the Bugzilla Bug Tracking System.
# 
# The Initial Developer of the Original Code is Netscape Communications
# Corporation. Portions created by Netscape are Copyright (C) 1998
# Netscape Communications Corporation. All Rights Reserved.
# 
# Contributor(s): TomWij <TomWij@live.com>

##############################################################################
#
# updateDatabase.cgi
# ---------------------
# Updates the MySQL database to include a 'suggestions' table.
#
##############################################################################

use DBI;
use DBD::mysql;

print "Content-type: text/html\n\n";

# Connect to the MySQL database.
do '..\..\..\localconfig';
$driver = DBI->install_driver("mysql"); 
$connect = $driver->connect("DBI:mysql:database=$db_name;host=$db_host", $db_user, $db_pass, {}) or print "<b>MySQL: Connection failed.</b>";

# Drop an existing table if it exists.
$query = "DROP TABLE suggestions;";
$query_handle = $connect->prepare($query) or print "<b>MySQL: Query Preparation failed.</b>";
$query_handle->execute() or print ""; # Error surpressed, the table most likely doesn't exist.

# Add the 'suggestions' table to the MySQL database.
$query = "CREATE TABLE suggestions (id INT NOT NULL PRIMARY KEY AUTO_INCREMENT, bid INT NOT NULL, pid VARCHAR(50), cid VARCHAR(50), user VARCHAR(50), user_severity VARCHAR(50), algo_severity VARCHAR(50), choice_severity VARCHAR(50));";
$query_handle = $connect->prepare($query) or print "<b>MySQL: Query Preparation failed.</b>";
$query_handle->execute() or print "<b>MySQL: Query Execution failed.</b>";